#ifndef BASE_PROTOCOL_H
#define BASE_PROTOCOL_H

#include <QObject>
#include "basefindpacket.h"
#include "baseparsepacket.h"
#include "basesendpacket.h"

enum ProtocolType
{
    ProtocolType_YuanRui = 0,
    ProtocolType_QinFine,
    ProtocolType_QingBoHua,
    ProtocolType_SparkLink_AutoSampler,
};

class BaseProtocolData;
class BaseProtocol : public QObject
{
    Q_OBJECT
public:
    explicit BaseProtocol(QObject *parent = nullptr);
    virtual ~BaseProtocol();

    virtual bool setConfig(int id, const QVariant &var);
    virtual bool getConfig(int id, QVariant &var);

    virtual bool setProtocolCmd(int id, QVariant &var);
    virtual bool getProtocolCmd(int id, QVariant &var);

    void setName(const QString &name);
    QString getName() const;

    virtual ProtocolType getProtocolType();

signals:
    void requestSend(const QByteArray &ba);
    void parseCompleted(int id, const QVariant &data);

public slots:
    virtual void onWork(QList<ProtocolPacket> packets);

    virtual void onBaseTickTimeout();

protected:
    explicit BaseProtocol(BaseProtocolData &data, QObject *parent = nullptr);
    BaseProtocolData 	*m_d = nullptr;

    QString             m_name;
};

Q_DECLARE_METATYPE(ProtocolType);

#endif // BASEPROTOCOL_H
